home *** CD-ROM | disk | FTP | other *** search
/ Speccy ClassiX 1998 / Speccy ClassiX 98.iso / amiga_system / the_aminet / dev / gcc / libmat.lha / src / mmult.cc < prev    next >
C/C++ Source or Header  |  1980-01-01  |  609b  |  33 lines

  1. //                MATRIX LIB
  2. //            TOMMY JOHANSSON 1995
  3.  
  4. #include "matrix.h"
  5.  
  6. Matrix operator * (const Matrix& A,const Matrix& B)
  7. {
  8.     int r,k,q;
  9.     #ifdef DEBUG
  10.         puts("Multiplicerar tvσ matriser.");
  11.     #endif
  12.     if((A.n==1)&&(A.m==1)) return(A.koff[1][1]*B); // SkalΣr*Matris
  13.     if((B.n==1)&&(B.m==1)) return(B.koff[1][1]*A); // Matris*skalΣr
  14.     #ifdef CHECK
  15.         if(A.n!=B.m)
  16.         {
  17.             printf("Felaktiga dimensioner! %d<>%d\n",A.n,B.m);    
  18.             exit(0);
  19.         }
  20.     #endif
  21.     Matrix C(A.m,B.n);
  22.     for(r=1;r<=A.m;r++)
  23.     {
  24.         for(k=1;k<=B.n;k++)
  25.         {
  26.         C.koff[r][k]=0;
  27.         for(q=1;q<=B.m;q++)
  28.             C.koff[r][k]+=A.koff[r][q]*B.koff[q][k];
  29.         }
  30.     }
  31.     return(C);
  32. }
  33.